package com.oa.dao.impl;

import java.util.List;

import org.springframework.stereotype.Repository;

import com.oa.base.BaseDaoImpl;
import com.oa.dao.TopicDao;
import com.oa.entity.Topic;
@SuppressWarnings("unchecked")
@Repository("topicDao")
public class TopicDaoImpl extends BaseDaoImpl<Topic> implements TopicDao {

	
	public List<Topic> queryAllTopicById(String forumId) {
		return getSession().createQuery("from Topic t where t.forum=:forumId order by t.topicType DESC, t.lastUpdateTime DESC")
				.setString("forumId", forumId).list();
	}

	public Topic queryLastTopic(String forumId) {
		return (Topic) getSession().createQuery("from Topic t where t.postingTime=(select max(t2.postingTime) from Topic t2 where t2.forum=:forumId)")
				.setString("forumId", forumId).uniqueResult();
	}

	public Topic queryTopicByName(String postingTitle) {
		return (Topic) getSession().createQuery("from Topic t where t.postingTitle=:postingTitle")
				.setString("postingTitle", postingTitle).uniqueResult();
	}

	
	public boolean updatetopic(Object object) {
		try{
			getSession().update(object);
			return true;
		}catch(Exception e){
			return false;
		}
	}
	
}
